package com.hzj.controller.api;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.hzj.controller.utils.IPUtils;
import com.hzj.controller.utils.RedisUtil;
import com.hzj.pojo.Patient;
import com.hzj.pojo.UserInfo;
import com.hzj.service.PatientService;
import com.hzj.service.UserInfoService;
import com.hzj.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@RestController
@RequestMapping("/api/user/")
public class HZJApiController {
    @Autowired
    PatientService ps;
    @Autowired
    RedisUtil redisUtil;
    @Autowired
    UserInfoService uis;

    @PostMapping("/auth/findAll")
    public Result findAllPatient(HttpServletRequest request) {
        UserInfo userInfo = (UserInfo) redisUtil.get("userInfo"+ IPUtils.getIpAddr(request));

        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("user_id", userInfo.getId());

        List<Patient> list = ps.list(wrapper);

        return Result.ok(list);

    }
    @PostMapping("/auth/queryUserInfoById/{id}")
    UserInfo queryUserInfoById(@PathVariable Long id){
        UserInfo userInfo = uis.getById(id);
        return userInfo;
    }

}
